clear all
set more off 
version 12.0
set trace off
cap log close
pause off

* Set path
if "`c(username)'"=="YOUR USER NAME"{
	global home "YOUR PATH TO REPLICATION FOLDER"
}
	global code "$home/Code"
	global data "$home/Data"
	global output "$home/Output"

set scheme s1color

* Load custom regression table formatting do files
include "$code/Balance_reg_fe.do"
include "$code/Balance_reg.do"

* Load data
use "$data/indivs_merge.dta", clear


//////////////
// Table 1. Impacts of partial school reopening on adult labor supply
//////////////
{
preserve
keep if inlist(wave,1,2,3)
keep if age>17
su workinghrs_l7 if working_l7==1 & trt_ctl==0 & post==0
su hhag if urban==1 & trt_ctl==0 & post==0
ta sector if whoemployed_==1 & !missing(trt_ctl)
ta sector if hhent==1 & !missing(trt_ctl)

gen post_treat=(post==1 & trt_ctl==1)
replace post_treat=. if missing(trt_ctl)
gen post_mixed=(post==1 & trt_ctl==2)
replace post_mixed=. if missing(trt_ctl)

local vl working_l7 whoemployed_ hhag hhent workinghrs_l7 hoursnow agri_hrs enter_hrs

eststo clear
eststo res2: corr_table_regfe `vl', indvar(post_treat) otherindvars(post_mixed) controls() fe(id i.month) cluster(id)
eststo res3: corr_table_regfe `vl', indvar(post_mixed) otherindvars(post_treat) controls() fe(id i.month) cluster(id)

	local options     "label nonum se nonotes varwidth(45) noobs replace nomtitles wrap collabels(none) star(* 0.10 ** 0.05 *** 0.01) tex fragment longtable"  
	local optionsAT `options' mgroups(" N & \shortstack{ Control Mean \\ (SD)} & \shortstack{Post x Treat \\ (SE)} & \shortstack{Post x Mixed \\ (SE)}  ", span) 
	local optionsAT_qval `options' mgroups(" N & \shortstack{ Control Mean \\ (SD)} & \shortstack{Post x Treat \\ (SE)} & \shortstack{FDR \\ q-value} & \shortstack{Post x Mixed \\ (SE)} & \shortstack{FDR \\ q-value}  ", span) 

	esttab res2 res3 using "$output/Tables/table1.tex",  ///
		cells(    "N(fmt(%9.0f) pattern(1 0))  mean(fmt(%9.3f) pattern(1 0))  b(star fmt(%9.3f))"  ///
        ". sd(par fmt(%9.3f) pattern(1 0))   se(par fmt(%9.3f))  ") ///
         `optionsAT'
	esttab res2 res3 using "$output/Tables/table1_qvals.tex",  ///
		cells(    "N(fmt(%9.0f) pattern(1 0))  mean(fmt(%9.3f) pattern(1 0))  b(star fmt(%9.3f))  qvals(fmt(%9.3f))"  ///
        ". sd(par fmt(%9.3f) pattern(1 0))   se(par fmt(%9.3f))  ") ///
          `optionsAT_qval'	

restore
}

//////////////
// Figure 4/Table S2.1. Heterogeneity in effects on adult work hours in the last 7 days
//////////////

{
preserve
keep if inlist(wave,1,2,3)
keep if age>17
replace big_urban=0 if missing(big_urban)

su gender any_closure emp_closure ag_closure ent_closure if wave==3 & !missing(trt_ctl)
su gender any_closure emp_closure ag_closure ent_closure agever urban_0 big_urban private_skl if wave==3 & resp==1 & !missing(trt_ctl)

* Table
eststo clear
local groups gender any_closure emp_closure ag_closure ent_closure agever urban_0 big_urban private_skl 
foreach g of varlist `groups' {
		quietly: reghdfe workinghrs_l7 i.posttreat##i.`g' i.month##i.`g', absorb(id i.month) vce(cluster id)
		eststo `g': xlincom (Z0T=1.posttreat) (Z0M=2.posttreat) (Z1T=1.posttreat + 1.posttreat#1.`g') (Z1M=2.posttreat+ 2.posttreat#1.`g'), post
		test Z0T=Z1T
		local p1: display %4.3f `r(p)'
		estadd scalar p1= `p1'
		test Z0M=Z1M
		local p2: display %4.3f `r(p)'
		estadd scalar p2= `p2'
		su workinghrs_l7 if post==0 & trt_ctl==0 & e(sample)
		estadd scalar Mean = r(mean)
	}
esttab using "$output/Tables/het_chars.tex", ///
	scalars("Mean Mean, pre-reopen control" "p1 p-value Treated Z0=Z1" "p2 p-value Mixed Z0=Z1") /// 
	mlabels("Female" "\shortstack{Any work \\ during \\ closures }" "\shortstack{Any wage \\ employmt \\ during \\ closures }" ///
	"\shortstack{Any HH \\ ag work \\ during \\ closures }" "\shortstack{Any HH \\ ent. work \\ during \\ closures }" ///
	"\shortstack{Ag HH}" "\shortstack{Urban \\ location}" "\shortstack{Large \\ urban \\ location}" ///
	"\shortstack{Any child in \\ private \\ school }") ///		
	star(* 0.10 ** 0.05 *** 0.01) ///
	addnote("SEs clustered at household level.") ///
	b(2) se(2) varwidth(45) num nonotes label replace booktabs nobaselevels obs f end( \\ )

* Coefplot
eststo clear
local groups gender any_closure emp_closure ag_closure ent_closure agever 
foreach g of varlist `groups' {
		quietly: reghdfe workinghrs_l7 i.posttreat##i.`g' i.month##i.`g', absorb(id i.month) vce(cluster id)
		eststo `g': xlincom (`g'0=1.posttreat) (`g'1=1.posttreat + 1.posttreat#1.`g'), post
	}
	
coefplot (agever, rename(agever0="Any HH agriculture" agever1="No HH agriculture")) ///
	(gender, rename(gender0="Men" gender1="Women")) ///
	(any_closure, rename(any_closure0="No work" any_closure1="Any work"))  ///
	(emp_closure, rename(emp_closure0="No wage work" emp_closure1="Any wage work"))  ///
	(ag_closure, rename(ag_closure0="No HH ag work" ag_closure1="Any HH ag work"))  ///
	(ent_closure, rename(ent_closure0="No non-ag ent. work" ent_closure1="Any non-ag ent. work"))  ///
	, ///
	levels(95) nokey msymbol(T) ///
	xline(0, lcolor(black) lpattern(dash)) grid(none) xlabel(-5(5)20)  ///
	headings("No work"= `""{it: Indiv. work}" "{it: during closures}""', gap(0.5)) ///
	text(1.4 0.2 "p=0.15" , color(gs8) size(med) placement(e)) ///
	text(3.4 0.2 "p=0.62" , color(gs8) size(med) placement(e)) ///
	text(7.0 0.2 "p=0.04" , color(gs8) size(med) placement(e)) ///
	text(9.0 0.2 "p=0.32" , color(gs8) size(med) placement(e)) ///
	text(11.0 0.2 "p=0.12" , color(gs8) size(med) placement(e)) ///
	text(13.0 0.2 "p=0.86" , color(gs8) size(med) placement(e)) 
graph export "$output/Graphs/het_basework.tif", replace
graph export "$output/Graphs/het_basework.pdf", replace

restore
}

//////////////
// Figures 5 and 6. Mechanism coef plots
//////////////
{
preserve
keep if inlist(wave,1,2,3) 
keep if age>17
bys wealth_0: su hired_ag if wave<3 & agever==1 & resp==1 & !missing(trt_ctl)
replace hired_ag=0 if ag_hh==0
replace childcare_hr=0 if missing(childcare_hr)
ren workinghrs_l7 whr
ren nonagri_hrs nahr
ren childcare_hr chhr
ren s4_q2_hours_allchild chaghr
ren hired_ag hirag

eststo clear
foreach k of varlist whr nahr {
	quietly eststo `k': reghdfe `k' i.posttreat, absorb(id i.month) vce(cluster id)
}
foreach k of varlist chhr chaghr hirag {
	quietly eststo `k': reghdfe `k' i.posttreat if resp==1, absorb(id i.month) vce(cluster id)
}
foreach k of varlist whr nahr {
foreach z of varlist only_child young_kids trt_girl anygrade8 anychildag wealth_0 {
	quietly reghdfe `k' i.posttreat##i.`z' i.month##i.`z', absorb(id i.month) vce(cluster id)
	eststo `k'`z': xlincom (`k'`z'0=1.posttreat) (`k'`z'1=1.posttreat + 1.posttreat#1.`z'), post
	}
}
foreach k of varlist chhr chaghr hirag {
foreach z of varlist only_child young_kids trt_girlv anygrade8 anychildagpre wealth_00 {
	quietly reghdfe `k' i.posttreat##i.`z' i.month##i.`z' if resp==1, absorb(id i.month) vce(cluster id)
	eststo `k'`z': xlincom (`k'`z'0=1.posttreat) (`k'`z'1=1.posttreat + 1.posttreat#1.`z'), post
	}
}

restore
	
coefplot (whr, rename(1.posttreat="All households") keep(1.posttreat)) ///
	(whronly_child, rename(whronly_child0="Multiple children" whronly_child1="Only one child")) ///
	(whryoung_kids, rename(whryoung_kids0="No siblings age 0-4" whryoung_kids1="Any siblings age 0-4"))  ///
	(whrtrt_girl, rename(whrtrt_girl0="Boy treated child" whrtrt_girl1="Girl treated child"))  ///
	(whranygrade8, rename(whranygrade80="Grade 4 treated child" whranygrade81="Grade 8 treated child"))  ///
	, ///
	levels(95) nokey msymbol(T) ///
	xline(0, lcolor(black) lpattern(dash)) grid(none) xlabel(-5(5)15) ///
	text(2.5 0.2 "p=0.96" , color(gs6) size(med) placement(e)) ///
	text(4.5 0.2 "p=0.76" , color(gs6) size(med) placement(e)) ///
	text(6.5 0.2 "p=0.12" , color(gs6) size(med) placement(e)) ///
	text(8.5 0.2 "p=0.54" , color(gs6) size(med) placement(e)) ///
	title("B. Adult work hours") ylabel(,labsize(large))
graph export "$output/Graphs/mech_wkhrs_1.tif", replace
graph export "$output/Graphs/mech_wkhrs_1.pdf", replace

coefplot (chhr, rename(1.posttreat="All households") keep(1.posttreat)) ///
	(chhronly_child, rename(chhronly_child0="Multiple children" chhronly_child1="Only one child")) ///
	(chhryoung_kids, rename(chhryoung_kids0="No siblings age 0-4" chhryoung_kids1="Any siblings age 0-4"))  ///
	(chhrtrt_girlv, rename(chhrtrt_girlv0="Boy treated child" chhrtrt_girlv1="Girl treated child"))  ///
	(chhranygrade8, rename(chhranygrade80="Grade 4 treated child" chhranygrade81="Grade 8 treated child"))  ///
	, ///
	levels(95) nokey msymbol(T) ///
	xline(0, lcolor(black) lpattern(dash)) grid(none) xlabel(-20(10)30) ///
	text(2.5 0.2 "p=0.60" , color(gs6) size(med) placement(e)) ///
	text(4.5 0.2 "p=0.24" , color(gs6) size(med) placement(e)) ///
	text(6.5 0.2 "p=0.39" , color(gs6) size(med) placement(e)) ///
	text(8.5 0.2 "p=0.89" , color(gs6) size(med) placement(e))  ///
	title("A. Respondent childcare hours") ylabel(,labsize(large))
graph export "$output/Graphs/mech_cchrs.tif", replace
graph export "$output/Graphs/mech_cchrs.pdf", replace

coefplot (whr, rename(1.posttreat="All households") keep(1.posttreat)) ///
	(whronly_child, rename(whronly_child0="Multiple children" whronly_child1="Only one child")) ///
	(whrtrt_girl, rename(whrtrt_girl0="Boy treated child" whrtrt_girl1="Girl treated child"))  ///
	(whranychildag, rename(whranychildag0="No child HH ag work" whranychildag1="Any child HH ag work"))  ///
	(whrwealth_0, rename(whrwealth_00="Below mean wealth" whrwealth_01="Above mean wealth"))  ///
	, ///
	levels(95) nokey msymbol(T) ///
	xline(0, lcolor(black) lpattern(dash)) grid(none) xlabel(-5(5)15) ///
	text(2.5 0.2 "p=0.96" , color(gs6) size(med) placement(e)) ///
	text(4.5 0.2 "p=0.12" , color(gs6) size(med) placement(e)) ///
	text(6.5 0.2 "p=0.12" , color(gs6) size(med) placement(e)) ///
	text(8.5 0.2 "p=0.05" , color(gs6) size(med) placement(e))  ///
	title("B. Adult work hours") ylabel(,labsize(large))
graph export "$output/Graphs/mech_wkhrs_2.tif", replace
graph export "$output/Graphs/mech_wkhrs_2.pdf", replace

coefplot (chaghr, rename(1.posttreat="All households") keep(1.posttreat)) ///
	(chaghronly_child, rename(chaghronly_child0="Multiple children" chaghronly_child1="Only one child")) ///
	(chaghrtrt_girlv, rename(chaghrtrt_girlv0="Boy treated child" chaghrtrt_girlv1="Girl treated child"))  ///
	(chaghranychildagpre, rename(chaghranychildagpre0="No child HH ag work" chaghranychildagpre1="Any child HH ag work"))  ///
	(chaghrwealth_00, rename(chaghrwealth_000="Below mean wealth" chaghrwealth_001="Above mean wealth"))  ///
	, ///
	levels(95) nokey msymbol(T) ///
	xline(0, lcolor(black) lpattern(dash)) grid(none) xlabel(-10(5)10) ///
	text(2.5 0.2 "p=0.21" , color(gs6) size(med) placement(e)) ///
	text(4.5 0.2 "p=0.15" , color(gs6) size(med) placement(e)) ///
	text(6.5 0.2 "p=0.24" , color(gs6) size(med) placement(e)) ///
	text(8.5 0.2 "p=0.12" , color(gs6) size(med) placement(e))  ///
	title("A. Total child HH ag. hours") ylabel(,labsize(large))
graph export "$output/Graphs/mech_chaghrs.tif", replace
graph export "$output/Graphs/mech_chaghrs.pdf", replace

coefplot (hirag, rename(1.posttreat="All households") keep(1.posttreat)) ///
	(hiragonly_child, rename(hiragonly_child0="Multiple children" hiragonly_child1="Only one child")) ///
	(hiragtrt_girlv, rename(hiragtrt_girlv0="Boy treated child" hiragtrt_girlv1="Girl treated child"))  ///
	(hiraganychildagpre, rename(hiraganychildagpre0="No child HH ag work" hiraganychildagpre1="Any child HH ag work"))  ///
	(hiragwealth_00, rename(hiragwealth_000="Below mean wealth" hiragwealth_001="Above mean wealth"))  ///
	,  ///
	levels(95) nokey msymbol(T) ///
	xline(0, lcolor(black) lpattern(dash)) grid(none) xlabel(-0.1(0.1)0.3) ///
	text(2.5 0.01 "p=0.71" , color(gs6) size(med) placement(e)) ///
	text(4.5 0.01 "p=0.92" , color(gs6) size(med) placement(e)) ///
	text(6.5 0.01 "p=0.27" , color(gs6) size(med) placement(e)) ///
	text(8.5 0.01 "p=0.36" , color(gs6) size(med) placement(e))  ///
	title("C. Any hired ag labor")  ylabel(,labsize(large))
graph export "$output/Graphs/mech_hiraghrs.tif", replace
graph export "$output/Graphs/mech_hiraghrs.pdf", replace
}


